package com.turing.post.report.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 销售商分支机构业务日结单
 * 
 * @author yxb
 * 
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "BranchDaySett")
@IdClass(BranchDaySett.class)
public class BranchDaySett implements Serializable {

	public BranchDaySett() {
		super();
	}

	/**
	 * 销售商机构号
	 */
	private String saleBranchNo;

	/**
	 * 账务日期
	 */
	private Date tranDate;

	/**
	 * 业务类型
	 */
	private String tranType;

	/**
	 * 笔数
	 */
	private BigInteger tranCount = BigInteger.ZERO;

	/**
	 * 现金发生额(>0收入,<0支出,下同)
	 */
	private BigInteger cashAmount = BigInteger.ZERO;

	/**
	 * 转账发生额
	 */
	private BigInteger tranAmount = BigInteger.ZERO;

	/**
	 * 支票发生额
	 */
	private BigInteger chequeAmount = BigInteger.ZERO;

	/**
	 * 授信发生额
	 */
	private BigInteger creditAmount = BigInteger.ZERO;

	/**
	 * 现金手续费
	 */
	private BigInteger cashFee = BigInteger.ZERO;

	/**
	 * 转账手续费
	 */
	private BigInteger tranFee = BigInteger.ZERO;

	/**
	 * 支票手续费
	 */
	private BigInteger chequeFee = BigInteger.ZERO;

	/**
	 * 授信手续费
	 */
	private BigInteger creditFee = BigInteger.ZERO;

	/**
	 * 卡内扣手续费
	 */
	private BigInteger cardFee = BigInteger.ZERO;

	/**
	 * 手续费优惠
	 */
	private BigInteger discountFee = BigInteger.ZERO;

	/**
	 * 赎回发生额
	 */
	private BigInteger redempAmount = BigInteger.ZERO;

	@Id
	@Column(name = "SaleBranchNo", nullable = false)
	public String getSaleBranchNo() {
		return saleBranchNo;
	}

	public void setSaleBranchNo(String saleBranchNo) {
		this.saleBranchNo = saleBranchNo;
	}

	@Id
	@Column(name = "TranDate", nullable = false)
	public Date getTranDate() {
		return tranDate;
	}

	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}

	/**
	 * 01-售卡
	 */
	public final static String TRANTYPE_SALE = "01";
	/**
	 * 91-售卡取消
	 */
	public final static String TRANTYPE_SALE_CANCEL = "91";
	/**
	 * 02-充值
	 */
	public final static String TRANTYPE_DEPOSIT = "02";
	/**
	 * 92-充值取消
	 */
	public final static String TRANTYPE_DEPOSIT_CANCEL = "92";
	/**
	 * 03-赎回
	 */
	public final static String TRANTYPE_REDEMP = "03";
	/**
	 * 04-正式挂失
	 */
	public final static String TRANTYPE_LOSS = "04";
	/**
	 * 05-挂失换卡
	 */
	public final static String TRANTYPE_LOSS_REISSUE = "05";
	/**
	 * 06-换发新卡
	 */
	public final static String TRANTYPE_REISSUE = "06";
	/**
	 * 07-卡延期
	 */
	public final static String TRANTYPE_EXPIRED = "07";
	/**
	 * 08-重置密码
	 */
	public final static String TRANTYPE_RESET_PWD = "08";
	/**
	 * 09-变更卡种类
	 */
	public final static String TRANTYPE_CARDCLASSIC = "09";
	/**
	 * 10-登记实名信息
	 */
	public final static String TRANTYPE_REALNAME = "10";
	/**
	 * 11-现金上缴
	 */
	public final static String TRANTYPE_DELIVERY = "11";
	/**
	 * 12-授信缴款
	 */
	public final static String TRANTYPE_CREDIT = "12";
	/**
	 * 13-补磁
	 */
	public final static String TRANTYPE_MAGNETIC = "13";
	/**
	 * 20-临时挂失
	 */
	public static final String TRANTYPE_TEMPORARYLOSS = "20";
	/**
	 * 21-卡解挂失
	 */
	public static final String TRANTYPE_RELIEVELOSS = "21";
	/**
	 * 22-卡改密
	 */
	public static final String TRANTYPE_MODIFYPASSWD = "22";
	/**
	 * 23-卡冻结
	 */
	public static final String TRANTYPE_FREEZE = "23";
	/**
	 * 24-解卡冻结
	 */
	public static final String TRANTYPE_FREEZESOLUTION = "24";
	/**
	 * 25-卡锁定
	 */
	public static final String TRANTYPE_LOCK = "25";
	/**
	 * 26-解卡锁定
	 */
	public static final String TRANTYPE_LOCKFREE = "26";
	/**
	 * 27-解除卡密码锁定
	 */
	public static final String TRANTYPE_PWDUNLOCK = "27";
	/**
	 * 28-账户管理费
	 */
	public static final String TRANTYPE_MANAGEMENTFEE = "28";
	/**
	 * 29-过期管理费
	 */
	public static final String TRANTYPE_EXPIREDMANAGEMENTFEE = "29";

	@Id
	@Column(name = "TranType", nullable = false)
	public String getTranType() {
		return tranType;
	}

	public void setTranType(String tranType) {
		this.tranType = tranType;
	}

	@Column(name = "TranCount", nullable = false)
	public BigInteger getTranCount() {
		return tranCount;
	}

	public void setTranCount(BigInteger tranCount) {
		this.tranCount = tranCount;
	}

	@Column(name = "CashAmount", nullable = false)
	public BigInteger getCashAmount() {
		return cashAmount;
	}

	public void setCashAmount(BigInteger cashAmount) {
		this.cashAmount = cashAmount;
	}

	@Column(name = "TranAmount", nullable = false)
	public BigInteger getTranAmount() {
		return tranAmount;
	}

	public void setTranAmount(BigInteger tranAmount) {
		this.tranAmount = tranAmount;
	}

	@Column(name = "ChequeAmount", nullable = false)
	public BigInteger getChequeAmount() {
		return chequeAmount;
	}

	public void setChequeAmount(BigInteger chequeAmount) {
		this.chequeAmount = chequeAmount;
	}

	@Column(name = "CreditAmount", nullable = false)
	public BigInteger getCreditAmount() {
		return creditAmount;
	}

	public void setCreditAmount(BigInteger creditAmount) {
		this.creditAmount = creditAmount;
	}

	@Column(name = "CashFee", nullable = false)
	public BigInteger getCashFee() {
		return cashFee;
	}

	public void setCashFee(BigInteger cashFee) {
		this.cashFee = cashFee;
	}

	@Column(name = "TranFee", nullable = false)
	public BigInteger getTranFee() {
		return tranFee;
	}

	public void setTranFee(BigInteger tranFee) {
		this.tranFee = tranFee;
	}

	@Column(name = "ChequeFee", nullable = false)
	public BigInteger getChequeFee() {
		return chequeFee;
	}

	public void setChequeFee(BigInteger chequeFee) {
		this.chequeFee = chequeFee;
	}

	@Column(name = "CardFee", nullable = false)
	public BigInteger getCardFee() {
		return cardFee;
	}

	public void setCardFee(BigInteger cardFee) {
		this.cardFee = cardFee;
	}

	@Column(name = "CreditFee", nullable = false)
	public BigInteger getCreditFee() {
		return creditFee;
	}

	public void setCreditFee(BigInteger creditFee) {
		this.creditFee = creditFee;
	}

	@Column(name = "DiscountFee", nullable = false)
	public BigInteger getDiscountFee() {
		return discountFee;
	}

	public void setDiscountFee(BigInteger discountFee) {
		this.discountFee = discountFee;
	}

	public void setRedempAmount(BigInteger redempAmount) {
		this.redempAmount = redempAmount;
	}

	public BigInteger getRedempAmount() {
		return redempAmount;
	}

	public boolean isAllZero() {
		if (!BigInteger.ZERO.equals(getTranCount()))
			return false;

		if (!BigInteger.ZERO.equals(getCashAmount()))
			return false;

		if (!BigInteger.ZERO.equals(getTranAmount()))
			return false;

		if (!BigInteger.ZERO.equals(getChequeAmount()))
			return false;

		if (!BigInteger.ZERO.equals(getRedempAmount()))
			return false;

		if (!BigInteger.ZERO.equals(getCashFee()))
			return false;

		if (!BigInteger.ZERO.equals(getTranFee()))
			return false;

		if (!BigInteger.ZERO.equals(getChequeFee()))
			return false;

		if (!BigInteger.ZERO.equals(getCardFee()))
			return false;

		if (!BigInteger.ZERO.equals(getDiscountFee()))
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		return PCPSUtil.getObjectListHashCode(new Object[] { getSaleBranchNo(),
				getTranDate(), getTranType() });
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof BranchDaySett))
			return false;

		BranchDaySett other = (BranchDaySett) obj;

		if (!PCPSUtil.compareObject(this.getSaleBranchNo(), other
				.getSaleBranchNo()))
			return false;

		if (!PCPSUtil.compareObject(this.getTranDate(), other.getTranDate()))
			return false;

		return PCPSUtil.compareObject(this.getTranType(), other.getTranType());
	}
}